package com.jiuzhe.commercial.ui.house;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.jiuzhe.commercial.R;
import com.jiuzhe.commercial.base.BaseActivity;
import com.jiuzhe.commercial.constant.Constants;
import com.jiuzhe.commercial.utils.UIUtils;
import com.squareup.timessquare.CalendarPickerView;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;

import static com.jiuzhe.commercial.constant.Constants.TODAY;
import static com.squareup.timessquare.CalendarPickerView.SelectionMode.RANGE;

/**
 * Created by huanghao on 2018/5/7.
 */

public class CalendarActivity2 extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.calendar_view)
    CalendarPickerView calendarView;
    String from = "";

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.calendar_activity);
        setTitle("日期选择");
        setRringTitle("确定");
        initData();
    }

    private void initData() {
        Calendar nextYear = Calendar.getInstance();
        nextYear.add(Calendar.YEAR, 1);
        Date today = new Date();
        calendarView.init(today, nextYear.getTime())
                .inMode(RANGE);
        TODAY = today;
        tv_right.setOnClickListener(this);
    }


    @Override
    protected void loadData() {


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        if (intent != null) {
            from = intent.getStringExtra("from");
        }
    }

    @Override
    public void onClick(View v) {
        List<Date> dateList = calendarView.getSelectedDates();
        int size = dateList.size();
        if (size >= 7 && size <= 14) {
            Constants.TIME_ROOM = dateList;
            /*if (!"MainActivity".equals(from)) {
                UIUtils.startActivity(ListingActivity.class);
            }*/
            finish();
        } else
            UIUtils.showToastSafe("请选择1—2个星期的时间段");
    }
}
